
#include "Appointment.h" 

using namespace std;




Time::Time(int h,int min) : hour(h), minutes(min){}

int Time::getHour() const
{
	return hour;
}

int Time::getMinutes() const
{
	return minutes;
}

bool Time::operator<(Time const & other) const
{
	if (hour < other.hour) return true;
	else if (hour > other.hour) return false;
	else return minutes < other.minutes;
}

bool Time::operator>(Time const & other) const
{
	return !(*this<=other);
}

bool Time::operator<=(Time const & other) const
{
	return !(other<*this); 
}

bool Time::operator>=(Time const & other) const
{
	return !(*this<other); 
}

bool Time::operator==(Time const & other) const
{
	return (*this<=other) && (*this>=other);
}

bool Time::operator!=(Time const & other) const
{
	return !(*this==other);
}


Appointment::Appointment(Time const & start,Time const & end,Day const & day, string const & subj) :
startTime(start),endTime(end),day(day),subject(subj) {}

Appointment::~Appointment(){}

bool Appointment::operator<(Appointment const & other) const
{
	Time minEndTime = min(endTime, other.endTime);
	Time maxStartTime = max(startTime, other.startTime);
	return (day < other.day) || (startTime < other.startTime) && (minEndTime<maxStartTime);
}

bool Appointment::operator>(Appointment const & other) const
{
	return !(*this<=other);
}

bool Appointment::operator<=(Appointment const & other) const
{
	return !(other<*this); 
}

bool Appointment::operator>=(Appointment const & other) const
{
	return !(*this<other); 
}

bool Appointment::operator==(Appointment const & other) const
{
	return (*this<=other) && (*this>=other);
}

bool Appointment::operator!=(Appointment const & other) const
{
	return !(*this==other);
}

Time Appointment::getStartTime() const
{
	return this->startTime; 
}

Time Appointment::getEndTime() const
{
	return this->endTime;
}

string Appointment::getSubject() const
{
	return subject;
}

Day Appointment::getDay() const
{
	return day;
}

bool Appointment::compare(Appointment const * a, Appointment const * b) 
{
	return (*a)<(*b);
}

Day intToDay(int n)
{
  switch( n )
  {
    case 1 :  return Sunday;
    case 2 : return Monday;
	case 3 :  return Tuesday;
    case 4 : return Wednesday;
    case 5 : return Thursday;
    case 6 : return Friday;
	case 7 : return Saturday;
	default: throw n;
  }
}

int dayToInt(Day d)
{
  switch( d )
  {
    case Sunday :  return 1;
    case Monday : return 2;
	case Tuesday :  return 3;
    case Wednesday : return 4;
    case Thursday : return 5;
    case Friday : return 6;
	case Saturday : return 7;
	default : return 0;
  }
}
ostream& operator<<(ostream& os,Time const & t)
{
	if(t.getHour() < 10)
	{
		os << 0;
	}
	os << t.getHour();
	os << ":";
	if(t.getMinutes() < 10)
	{
		os << 0;
	}
	os << t.getMinutes();
	return os;
}

ostream& operator<<(ostream& os,Appointment const & app)
{
	return os << app.getDay() << " " << app.getStartTime() << "-" << app.getEndTime() << " " << app.getSubject();
}

ostream& operator<<(ostream& os,Day const & d)
{
	os << left;
	switch ( d )
	{
	case Sunday :  return os << "Sunday";
    case Monday : return os<<"Monday";
	case Tuesday :  return os<<"Tuesday";
    case Wednesday : return os<<"Wednesday";
    case Thursday : return os<<"Thursday";
    case Friday : return os<<"Friday";
	case Saturday : return os<<"Saturday";
	default : return os<<"Unspecified";
	}
}